package com.alibaba.dubbo.remoting.interceptor;

import java.net.InetAddress;

import com.alibaba.dubbo.common.inet.InetAddressProvider;
import com.alibaba.dubbo.common.inet.ipv4.AddressMatcher;

/**
 * 
 * @author kingbo.ruan 
 * @time 2014年9月25日 上午8:43:25
 */
public class MixedListInterceptorBasedAddressProvider extends MixedListInterceptor {

	private AddressMatcher matcherWhite = null;
	private InetAddressProvider providerWhite = null;
	private AddressMatcher matcherBlack = null;
	private InetAddressProvider providerBlack = null;

	@Override
	protected boolean matchBlack(InetAddress address) {
		// 是否有同步问题？
		if (matcherBlack == null) {
			matcherBlack = new AddressMatcher();
			if (providerBlack != null) {
				matcherBlack.setInetAddressProvider(providerBlack);
			}
		}

		return matcherBlack.match(address);
	}

	@Override
	protected boolean matchWhite(InetAddress address) {
		// 是否有同步问题？
		if (matcherWhite == null) {
			matcherWhite = new AddressMatcher();
			if (providerWhite != null) {
				matcherWhite.setInetAddressProvider(providerWhite);
			}
		}

		return matcherWhite.match(address);
	}

	public InetAddressProvider getProviderWhite() {
		return providerWhite;
	}

	public void setProviderWhite(InetAddressProvider providerWhite) {
		this.providerWhite = providerWhite;
	}

	public InetAddressProvider getProviderBlack() {
		return providerBlack;
	}

	public void setProviderBlack(InetAddressProvider providerBlack) {
		this.providerBlack = providerBlack;
	}
}
